package STUDENT.HOANGQUOCVIET.OOPs.QuanLyNhanSu.Views;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import org.eclipse.wb.swing.FocusTraversalOnArray;

import com.sun.xml.internal.ws.api.message.Message;

import STUDENT.HOANGQUOCVIET.OOPs.QuanLyNhanSu.Controllers.Controller;
import STUDENT.HOANGQUOCVIET.OOPs.QuanLyNhanSu.Models.Model;

import java.awt.Component;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

public class jFThemNV extends JFrame {

	private JPanel contentPane;
	private JTextField txtMaNV;
	private JTextField txtTenNV;
	private JTextField txtDiaChi;
	private JTextField txtBacLuong;
	private JTextField txtSDT;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					jFThemNV frame = new jFThemNV();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public jFThemNV() {
		setResizable(false);
		setFont(new Font("Times New Roman", Font.PLAIN, 18));
		setTitle("Thêm Nhân Viên");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 521, 322);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JLabel lblMNhnVin = new JLabel("Mã Nhân Viên:");
		lblMNhnVin.setFont(new Font("Times New Roman", Font.PLAIN, 17));

		txtMaNV = new JTextField();
		txtMaNV.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				if (txtMaNV.getText().isEmpty()) {
					txtMaNV.requestFocus();
				}

			}
		});
		txtMaNV.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		txtMaNV.setColumns(10);

		JLabel lblNewLabel = new JLabel("Tên Nhân Viên");
		lblNewLabel.setFont(new Font("Times New Roman", Font.PLAIN, 18));

		txtTenNV = new JTextField();
		txtTenNV.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		txtTenNV.setColumns(10);

		JLabel lblaCh = new JLabel("Địa chỉ");
		lblaCh.setFont(new Font("Times New Roman", Font.PLAIN, 18));

		txtDiaChi = new JTextField();
		txtDiaChi.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		txtDiaChi.setColumns(10);

		JLabel lblSinThoi = new JLabel("Số Điện Thoại");
		lblSinThoi.setFont(new Font("Times New Roman", Font.PLAIN, 18));

		JLabel lblHS = new JLabel("Bậc Lương");
		lblHS.setFont(new Font("Times New Roman", Font.PLAIN, 18));

		txtBacLuong = new JTextField();
		txtBacLuong.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		txtBacLuong.setColumns(10);

		JButton btnThem = new JButton("Thêm Nhân Viên");
		btnThem.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				 Controller objController = new Controller();
				 try {
					 objController.setMaNV(Integer.parseInt(txtMaNV.getText().trim()));
					 objController.setBacLuong(Double.parseDouble(txtBacLuong.getText().trim()));
					 objController.setHoTen(txtTenNV.getText().trim());
					 objController.setDiaChi(txtDiaChi.getText().trim());
					 objController.setSDT(txtSDT.getText().trim());
					 objController.Run(1);
				} catch (Exception e2) {
					// TODO: handle exception
				}
			}
		});
		btnThem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnThem.setFont(new Font("Times New Roman", Font.PLAIN, 18));

		txtSDT = new JTextField();
		txtSDT.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		txtSDT.setColumns(10);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane
				.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(
						gl_contentPane.createSequentialGroup().addContainerGap().addGroup(gl_contentPane
								.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane.createSequentialGroup()
										.addComponent(lblaCh, GroupLayout.PREFERRED_SIZE,
												111, GroupLayout.PREFERRED_SIZE)
										.addGap(39)
										.addComponent(txtDiaChi, GroupLayout.PREFERRED_SIZE, 146,
												GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(btnThem).addGap(
												49))
								.addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane
										.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPane.createSequentialGroup().addComponent(lblMNhnVin)
												.addGap(48).addComponent(txtMaNV, GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
										.addGroup(gl_contentPane.createSequentialGroup().addComponent(lblNewLabel)
												.addGap(39).addComponent(txtTenNV, GroupLayout.PREFERRED_SIZE, 146,
														GroupLayout.PREFERRED_SIZE))
										.addGroup(gl_contentPane.createSequentialGroup()
												.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
														.addComponent(lblHS, GroupLayout.PREFERRED_SIZE, 111,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(lblSinThoi, GroupLayout.PREFERRED_SIZE, 111,
																GroupLayout.PREFERRED_SIZE))
												.addGap(39)
												.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
														.addComponent(txtSDT, GroupLayout.PREFERRED_SIZE, 146,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(txtBacLuong, GroupLayout.PREFERRED_SIZE, 146,
																GroupLayout.PREFERRED_SIZE))))
										.addContainerGap(189, Short.MAX_VALUE)))));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane
				.createSequentialGroup()
				.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup().addContainerGap()
								.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
										.addComponent(lblMNhnVin).addComponent(txtMaNV, GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
								.addGap(14)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
										.addComponent(lblNewLabel).addComponent(txtTenNV, GroupLayout.PREFERRED_SIZE,
												28, GroupLayout.PREFERRED_SIZE))
								.addGap(18)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPane.createSequentialGroup().addGap(3).addComponent(lblaCh,
												GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
										.addComponent(txtDiaChi, GroupLayout.PREFERRED_SIZE, 28,
												GroupLayout.PREFERRED_SIZE))
								.addGap(21)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
										.addComponent(lblSinThoi, GroupLayout.PREFERRED_SIZE, 22,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(txtSDT, GroupLayout.PREFERRED_SIZE, 28,
												GroupLayout.PREFERRED_SIZE))
								.addGap(21)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPane.createSequentialGroup().addGap(3).addComponent(lblHS,
												GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
										.addComponent(txtBacLuong, GroupLayout.PREFERRED_SIZE, 28,
												GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_contentPane.createSequentialGroup().addGap(90).addComponent(btnThem)))
				.addContainerGap(55, Short.MAX_VALUE)));
		contentPane.setLayout(gl_contentPane);
		contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { txtMaNV, txtTenNV, txtDiaChi,
				txtSDT, txtBacLuong, btnThem, lblaCh, lblMNhnVin, lblNewLabel, lblSinThoi, lblHS }));
	}
}
